<?php 
/*
CREATE TABLE  `prefix_xtext_file` (
  `file_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `file_hash` char(32) CHARACTER SET latin1 NOT NULL,
  `file_parent_id` int(10) unsigned NOT NULL,
  `file_user_id` int(10) unsigned NOT NULL,
  `file_orig_name` varchar(64) COLLATE utf8_bin NOT NULL,
  `file_path` varchar(255) COLLATE utf8_bin NOT NULL,
  `file_upload_time` int(10) unsigned NOT NULL,
  `file_size` int(10) unsigned NOT NULL,
  `file_ext` char(14) COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`file_id`),
  KEY `index_2` (`file_parent_id`,`file_user_id`,`file_upload_time`),
  KEY `index_3` (`file_hash`),
  KEY `index_4` (`file_ext`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
 */


/**
 * This is the model class for table "prefix_xtext_file".
 *
 * The followings are the available columns in table 'prefix_xtext_file':
 * @property integer $file_id
 * @property string $file_hash
 * @property integer $file_parent_id
 * @property integer $file_user_id
 * @property string $file_orig_name
 * @property string $file_path
 * @property integer $file_upload_time
 * @property integer $file_size
 * @property string $file_ext
 */
class XtextFile extends LsActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Vote the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return Config::Get('plugin.xtext.table.file');
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('file_id, file_user_id, file_upload_time, file_size, file_parent_id, file_hash, file_orig_name, file_path, file_ext', 'required'),
			array('file_id, file_user_id, file_upload_time, file_size, file_parent_id', 'numerical', 'integerOnly'=>true),
			array('file_hash', 'length', 'max'=>32),
			array('file_orig_name', 'length', 'max'=>64),
			array('file_path', 'length', 'max'=>255),
			array('file_ext', 'length', 'max'=>14),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('file_id, file_user_id, file_upload_time, file_size, file_parent_id, file_hash, file_orig_name, file_path, file_ext', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'user' => array(self::BELONGS_TO, 'User', 'user_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'file_id' => 'File',
			'file_user_id' => 'User',
			'file_upload_time' => 'Upload Time',
			'file_size' => 'Size',
			'file_parent_id' => 'Parent',
			'file_hash' => 'Hash',
			'file_path' => 'Path',
			'file_orig_name' => 'Orig. Name',
			'file_ext' => 'Ext.',
		);
	}

}